package com.ethanzzh.security.core.ethanzzhdemo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;


//切片 可以拿到方法的参数真正被调用的值
//但是拿不到http请求和相应的对象
@Aspect
//@Component
public class TimeAspect {

    @Around("execution(* com.ethanzzh.security.core.ethanzzhdemo.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {

        System.out.println("time aspect start");

        Object [] args = pjp.getArgs();
        for (Object arg: args){
            System.out.println("arg is " + arg);
        }


        Long start = new Date().getTime();


        //该方法调用被拦截的控制器里面的方法
        Object object = pjp.proceed();

        //object 是控制器调用哪个方法的返回值
        System.out.println(object);

        System.out.println("time aspect耗时: "+ (new Date().getTime() - start));


        System.out.println("time aspect end");

        return object;
    }

}
